package com.yanqu.road.server.timer.union;

import com.yanqu.road.server.manager.union.activitygroup.UnionActivityGroupLockMgr;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.executor.GeneralTask;

public class CrossUnionActivityGroupCheckTask extends GeneralTask {

    private long reloadActivityTime = System.currentTimeMillis();
    private long checkGroupingTime = 0;
    private long syncGroupingTime = 0;

    @Override
    public void doRun() {
        try {
            // 每天23点50分刷新一次
            long now = System.currentTimeMillis();
            if (now > reloadActivityTime) {
                UnionActivityGroupLockMgr.reloadUnionActivityConfig();

                long today2350 = DateHelper.getZeroTimeStamp(now + DateHelper.DAY_MILLIONS) - DateHelper.MINUTE_MILLIONS * 10;
                if (reloadActivityTime >= today2350) {
                    reloadActivityTime = today2350 + DateHelper.DAY_MILLIONS;
                } else {
                    reloadActivityTime = today2350;
                }
            }
        } catch (Exception e) {
            getLOGGER().error("error : ", e);
        }

        try {
            // 1分钟检查一次分组
            if (System.currentTimeMillis() - checkGroupingTime > DateHelper.MINUTE_MILLIONS) {
                UnionActivityGroupLockMgr.checkGrouping();
                checkGroupingTime = System.currentTimeMillis();
            }
        } catch (Exception e) {
            getLOGGER().error("error : ", e);
        }

        try {
            // 1分钟检查一次分组同步情况
            if (System.currentTimeMillis() - syncGroupingTime > DateHelper.MINUTE_MILLIONS) {
                UnionActivityGroupLockMgr.checkSyncGroupInfo();
                syncGroupingTime = System.currentTimeMillis();
            }
        } catch (Exception e) {
            getLOGGER().error("error : ", e);
        }
    }

}
